package com.zhika.zishi.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;

import com.zhika.zishi.R;
import com.zhika.zishi.adapter.LikeStrategyPictureAdapter;
import com.zhika.zishi.customview.TitleView;
import com.zhika.zishi.interfaces.TitleInterface;

import java.util.ArrayList;

/**
 * Created by shi-02 on 2015/4/24.
 * 发布对比秀时，所参考攻略中的所有图片
 */
public class LikeStrategyPictureActivity extends BaseActivity {

    private GridView gridView;

    private ArrayList<String> pictureUrlList = new ArrayList<>();

    private LikeStrategyPictureAdapter pictureAdapter;

    private ImageView lastImageView = null;

    private TextView previewText;

    private TextView sureText;

    private TitleView titleView;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.like_strategy_picture);

        addTestData();

        initView();
    }

    private void initView(){
        gridView = (GridView) findViewById(R.id.like_strategy_picture_grid_view);
        pictureAdapter = new LikeStrategyPictureAdapter(LikeStrategyPictureActivity.this,pictureUrlList);
        gridView.setAdapter(pictureAdapter);
        gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                if (lastImageView != null){
                    lastImageView.setVisibility(View.GONE);
                }

                lastImageView = (ImageView) view.findViewById(R.id.item_of_like_strategy_picture_tab_image_view);
                lastImageView.setVisibility(View.VISIBLE);

                sureText.setBackground(getResources().getDrawable(R.drawable.text_3_shape));

            }
        });

        previewText = (TextView) findViewById(R.id.like_strategy_picture_preview_text);
        previewText.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(LikeStrategyPictureActivity.this,BigPictureActivity.class);
                startActivity(intent);
            }
        });

        sureText = (TextView) findViewById(R.id.like_strategy_picture_sure_text);
        sureText.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
               finish();
            }
        });

        String strategyTitleStr = "攻略标题";
        titleView = (TitleView) findViewById(R.id.like_strategy_picture_title_view);
        titleView.setLeftButtonText("返回");
        titleView.hideRightButton();
        titleView.setMiddleRowText("攻略："+strategyTitleStr);
        titleView.setTitleViewInterface(new TitleInterface() {
            @Override
            public void leftTitleListener() {
                finish();
            }

            @Override
            public void middleTitleListener() {

            }

            @Override
            public void rightTitleListener() {

            }
        });
    }

    private void addTestData(){
        for (int i = 0;i<12;i++){
            pictureUrlList.add("url");
        }
    }
}
